<?php
function getKeys($str){
    $preg = '/[\x{4e00}-\x{9fff}]+/u';
    if(preg_match($preg,$str,$matches)){
         $ch=$str;#join('',$matches);
         echo '<span style = "display:none;" var_str_simple='.$ch.'>'.$ch.'</span>';
         echo '<span style = "display:none;" var_str='.$ch.'>'.$ch.'</span>';
    }
}


if(@$_GET["type"]!=""){
    
    
    
    header("Cache-Control:no-cache,must-revalidate,no-store"); //这个no-store加了之后，Firefox下有效
    header("Pragma:no-cache");
    header("Expires:-1");
    switch($_GET["type"]){
        case "askneedreload":
            $time=date('Y-m-d H:i:s',time());;
            echo "console.log('加载完成','$time');";
            echo "$('#jsAskTime').html('$time');";
            echo "window.online=true;";
            break;
    }
    return;
}

if ( strlen($theme_config->background)>7 ){
    $url=$theme_config->background;
}else{
    $url="templates/$template/static/top-2.jpg";
}


header('Cache-Control:max-age=86400, must-revalidate');
header('Last-Modified:' . gmdate('D, d Y M H:i:s') . 'GMT');
header('Expires:' . gmdate('D, d Y M H:i:s', time()+'86400') . 'GMT');
?>


<!DOCTYPE html>
<html lang="zh-ch" xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta charset="utf-8" />
	<title><?php echo $site['title']; ?> - <?php echo $site['subtitle']; ?></title>
	<meta name="generator" content="EverEdit" />
	<meta name="referrer" content="never">
	
	<meta name="keywords" content="<?php echo $site['keywords']; ?>" />
	<meta name="description" content="<?php echo $site['description']; ?>" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link rel='stylesheet' href='static/mdui/css/mdui.css'>
	<link rel='stylesheet' href='static/jQuery-contextMenu/jquery.contextMenu.min.css'>
	<link rel="stylesheet" href="static/font-awesome/4.7.0/css/font-awesome.css">
	<link rel="stylesheet" href="templates/<?php echo $template; ?>/static/style.css?v=<?php echo $version; ?>">
	
	<link rel="stylesheet"                                   href="templates/<?php echo $template; ?>/static/font-awesome.min.css">
	<link rel='stylesheet'    id='iconfont-css'              href='templates/<?php echo $template; ?>/static/iconfont-3.03029.1.css'             type='text/css'     media='all'>
	
	<link rel='stylesheet' href='templates/<?php echo $template; ?>/static/bootstrap.min-3.03029.1.css'>
	<link rel="stylesheet" href="templates/<?php echo $template; ?>/static/fixstyle.css?v=<?php echo $version; ?>">
	<script src="templates/<?php echo $template; ?>/static/ChinesePY.js?v=<?php echo $version; ?>"/>
	<script>
	    function replaceThisTag(tag){
	        console.log("replace tag",tag)
	    }
	</script>
	 <meta http-equiv="Cache-Control" content="max-age=7200" />
	 
	<!--<script src = 'static/mdui/js/mdui.min.js'></script>-->
	<?php echo $site['custom_header']; ?>
	
	<style type="text/css">
 body{
   /*要设置滚动条的容器样式*/
   overflow: hidden;
 }
 body::-webkit-scrollbar {/*滚动条整体样式*/
   width: 5px;     /*高宽分别对应横竖滚动条的尺寸*/
   height: 1px;
 }
 body::-webkit-scrollbar-thumb {/*滚动条里面小方块*/
   border-radius: 10px;
   -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
   background: #535353;
 }
 .layui-layer-content{
     color:black;
 }
 body::-webkit-scrollbar-track {/*滚动条里面轨道*/
   -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
   border-radius: 10px;
   background: #EDEDED;
 }
</style>
</head>
<?php
	// 根据cookie来设置mdui主题
	$md_theme = $_COOKIE['docs-theme-layout'];
	if( empty($md_theme) || ( $md_theme == "light" ) ) {
		$md_theme = "";
	}
	else{
		$md_theme = "mdui-theme-layout-dark";
	}
?>

<!--mdui-appbar-with-toolbar mdui-drawer-body-left-->
<body class = "  <?php echo $md_theme ?> mdui-theme-primary-indigo mdui-theme-accent-pink mdui-loaded" style="background-image:url('<?php echo $url;?>');color:white;overflow:hidden;overflow-y:auto" onselectstart="return false">
    <img src="<?php echo $url;?>" referrerPolicy="no-referrer" style="display:none"/>

	<!--导航工具END-->
	
<div style="font-size:5px;float:right;text-align:right" t-onclick="debugShow(false);" id="debugTimeShow">
    <div>页面加载时间:<?php echo date('Y-m-d H:i:s',time());?></div>
    <div>请求时间:<a id="jsAskTime">正在加载</a></div>
</div>

	<!-- 添加按钮 -->
	<?php
		if( is_login() ) {
	?>	
	<div class="right-button mdui-hidden-xs" style="position: fixed;right:10px;bottom:80px;z-index:1000;">
		<div>
		<button title = "快速添加链接" id = "add" class="mdui-fab mdui-color-theme-accent mdui-ripple mdui-fab-mini"><i class="mdui-icon material-icons">add</i></button>
		</div>
	</div>
	<?php } ?>
	<div class="right-button mdui-hidden-xs" style="position: fixed;right:10px;bottom:130px;z-index:1000;">
		<div>
		    <button title = "后台管理" id = "add" class="mdui-fab mdui-color-theme-accent mdui-ripple mdui-fab-mini" onclick="window.open('/index.php?c=admin')"><i class="mdui-icon material-icons">account_circle</i></button>
		    
		<!--<a  target="_blank" class="mdui-btn mdui-btn-icon"></a>-->
		</div>
	</div>
	
	
	<!-- 添加按钮END -->
	<!-- 返回顶部按钮 -->
	<div id="top"></div>
	<div class="top mdui-shadow-10">
		<a href="javascript:;" title="返回顶部" onclick="gotop()"><i class="mdui-icon material-icons">arrow_drop_up</i></a>
	</div>
	
	
	<!-- 返回顶部END -->
	


<!-- 新版搜索框 -->
		 <div style="color:white;padding-top:120px;padding-bottom:20px">
		     
		     <div><center><h2>搜索</h2></center></div>
		     
		     
		 <div class="mdui-row" style="display:flex;justify-content: center;padding-top:40px;" >
		 <div class="mdui-col-md-3 mdui-col-xs-6 ">
				<div class="mdui-textfield mdui-textfield-floating-label">
					<!-- <label class="mdui-textfield-label">输入书签关键词进行搜索</label> -->
					<input id='input-search' autocomplete="off" class="input-search mdui-textfield-input search" style = "color:white;cursor:text" placeholder="输入书签关键词进行搜索" type="text" />
					<i class="mdui-icon material-icons" style = "color:white;position:absolute;right:2px;cursor:pointer">search</i>
				</div>
			</div>
		</div>
		<br>
		<center>
		    <small id="hitokoto" t-onclick="debugShow(true)"></small>
		</center>
		</div>

	<!--正文内容部分-->
	<div class="<?php echo ( $theme_config->full_width_mode == "off") ? "mdui-container" : "mdui-container-fluid"; ?>">
		<!-- 搜索框 -->
		<!-- <div class="mdui-row">
			<div class="mdui-col-xs-12" style = "z-index:99999;">
				<div class="mdui-textfield mdui-textfield-floating-label">
					<label class="mdui-textfield-label">输入书签关键词进行搜索</label>
					<input class="mdui-textfield-input search"  type="text" />
				</div>
			</div>
		</div> -->
		<!-- 搜索框END -->
		 
		<div >
		    <br>
		    
		</div>
		<div class="row url-card">
			<!-- 遍历分类目录 -->
            <?php foreach ( $categorys as $category ) {
                $fid = $category['id'];
                $links = get_links($fid);
				$font_icon = empty($category['font_icon']) ? '' : "<i class='{$category['font_icon']}'></i> ";
                //如果分类是私有的
                if( $category['property'] == 1 ) {
                    $property = '<i class="fa fa-expeditedssl" style = "color:#5FB878"></i>';
                }
                else {
                    $property = '';
                }
            ?>
			<div id = "category-<?php echo $category['id']; ?>" class = "mdui-col-xs-12 mdui-typo-title cat-title">
				<?php echo $font_icon; ?>
				<?php echo htmlspecialchars_decode($category['name']); ?> <?php echo $property; ?>
				<span class = "mdui-typo-caption"><?php echo $category['description']; ?></span>
			</div>
			<!-- 遍历链接 -->
			<?php
				foreach ($links as $link) {
					//默认描述
					$link['description'] = empty($link['description']) ? '作者很懒，没有填写描述。' : $link['description'];
					$id = $link['id'];
					//直链模式
					if( $site['link_model'] === 'direct' ) {
						$url = $link['url'];
					}
					else{
						$url = '/index.php?c=click&id='.$link['id'];
					}
				//var_dump($link);
			?>
			    <div class="url-card col-6  col-sm-6 col-md-4 col-xl-5a col-xxl-6a  link-space " id = "id_<?php echo $link['id']; ?>" link-title = "<?php echo $link['title']; ?>" link-url = "<?php echo $link['url']; ?>">
			            <!-- 用来搜索匹配使用 -->
                        <span style = "display:none;"><?php echo $link['url']; ?></span>
                        <?php getKeys($link['title'])?>
                        
                        <div class="url-body default">
                            <a href="<?echo $link['url'];?>" target="_blank" data-id="442" data-url="http://www.sust.edu.cn/" class="card no-c  mb-4 site-442" data-toggle="tooltip" data-placement="bottom" title="<?php echo $link['description']; ?>" data-original-title="">
                                <div class="card-body">
                                    <div class="url-content d-flex align-items-center">
                                        <div class="url-img rounded-circle mr-2 d-flex align-items-center justify-content-center">
                                            <!-- 网站图标显示方式 -->
										<?php if( $theme_config->favicon == "online") { ?>
											<img class="lazy loaded" src="https://favicon.rss.ink/v1/<?php echo base64($link['url']); ?>" alt="HUAN" width="25" height="25">
										<?php }else{ ?>
											<img class="lazy loaded"  src="/index.php?c=ico&text=<?php echo $link['title']; ?>" alt="" width="25" height="25" />
										<?php } ?>
                                        </div>
                                        <div class="url-info flex-fill">
                                            <div class="text-sm overflowClip_1">
                                                <strong style="text-overflow:ellipsis;white-space: nowrap;"><?php echo $link['title']; ?></strong>
                                            </div>
                                            <small  style="text-overflow:ellipsis;white-space: nowrap;"><p class="overflowClip_1 m-0 text-muted text-xs"> <?php echo $link['description']; ?> </p></small>
                                        </div>
                                    </div>
                                </div>
                            </a>
                            <a href="<?echo $link['url'];?>" class="togo text-center text-muted is-views" data-id="442" data-toggle="tooltip" data-placement="right" title="" rel="nofollow" data-original-title="">
								<i class="iconfont icon-goto"></i>
							</a>
                        </div>
                    </div>
                 
			</a>
			<?php } ?>
			<!-- 遍历链接END -->
			<?php } ?>
		</div>
		<!-- row end -->

		
	</div>
	<div class="mdui-divider" style = "margin-top:2em;"></div>
	<!--正文内容部分END-->
	<!-- footer部分 -->
	<footer>
		<?php if(empty( $site['custom_footer']) ){ ?>
		<!--© 2022 Powered by <a target = "_blank" href="https://github.com/helloxz/onenav" title = "简约导航/书签管理器" rel = "nofollow">OneNav</a>.The author is <a href="https://www.xiaoz.me/" target="_blank" title = "小z博客">xiaoz.me</a>-->
		<?php }else{
			echo $site['custom_footer'];
		} ?>
	</footer>
	<!-- footerend -->
</body>
<script src = 'static/js/jquery.min.js'></script>
<script src="static/layer/layer.js"></script>
<script src = 'static/jQuery-contextMenu/jquery.contextMenu.min.js'></script>
<script src = 'static/js/clipBoard.min.js'></script>
<script src = "templates/<?php echo $template; ?>/static/holmes.js"></script>

<script src = 'https://v1.hitokoto.cn/?encode=js&select=%23hitokoto'></script>

<script src="templates/<?php echo $template; ?>/static/embed.js?v=<?php echo $version; ?>"></script>
<script>
function isValidIP(ip) {
    var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
    return reg.test(ip);
}
function checkonLine(){
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "templates/<?php echo $template; ?>/index.php?type=askneedreload";
    script.onerror="$('#jsAskTime').html('<a style=\"color:red\">离线</a>')";
    script.on
    setTimeout(function() {
        if(!(window.online==true))
        $('#jsAskTime').html('<a style=\"color:red\">离线</a>');
        debugShow(true)
    }, 3*1000);
    document.getElementsByTagName("head")[0].appendChild(script);
    
}
function isURL(strUrl) {
  var regular = /\b([-a-z0-9]+(\.[-a-z0-9]+)*\.(?:com|edu|gov|int|mil|net|org|biz|info|name|museum|asia|coop|aero|[a-z][a-z]|((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]\d)|\d))\b(\/[-a-z0-9_:\@&?=+,.!\/~%\$]*)?)$/i;
  if (regular.test(strUrl)) {
    return true;
  } else {
    return false;
  }
}
function debugShow(show){
    if(show){
        $("#debugTimeShow").show();
    }else{
        $("#debugTimeShow").hide();
    }
    localStorage.setItem("debugShow",!!show);
}
debugShow(localStorage.getItem("debugShow")=="true")
$('input#input-search').focus()
checkonLine()

$(document).bind("keydown", function(e) {
    e = window.event || e;//解决浏览器兼容的问题   
    if(e.keyCode == 116) {//F5按下
        if(window.online==true){return true;}
    　　e.keyCode = 0;
    　　return false;
    　　
    }else{
    　　//刷新
    }
});
$('body').bind('keydown',function(event){
   
   if(!(document.activeElement !=null && document.activeElement.id=="input-search")){
       if(window.switchtime+100>new Date().getTime()){
           return;
       }
        $('input#input-search').focus()
        // console.log("body ")
     
   } 
});
$("[t-onclick]").each((i,obj)=>{
    // console.log($(obj))
    $(obj).click(function(){
        eval($(obj).attr("t-onclick"));
        console.log($(obj).attr("t-onclick"))
    })
})
$('input#input-search').bind('keydown',function(event){
    // console.log(event.keyCode)
    if(event.keyCode == "13") {
        
        // alert(1111);
        //   console.log(event)
        // return;
        if ($('.url-card.visible').length==0||event.shiftKey==true){
            url=$('input#input-search').val()
            if(isURL(url)){
                if(url.startsWith("http")){
                    location.href=url;
                }else{
                    location.href="http://"+url;
                }
                
            }else if(isValidIP(url)){
                location.href="http://"+url;
            }else{
                location.href="https://www.baidu.com/s?wd="+url;        
            }
        
        }else{
            let href=$('.url-card.visible >div>a').attr("href")
            location.href=href;
        }
        // window.open()
        
    }else if(event.keyCode == "27"){
        // if(document.activeElement !=null && document.activeElement.id=="input-search"){
            
            
            $('input#input-search').val("")
            $('input#input-search').blur()
            $('input#input-search').trigger('change');
            $('input#input-search').trigger('input');
            $(".cat-title").removeClass("mdui-hidden");
            let hal=$('[hidden="true"]');
            hal.removeAttr("hidden")
            hal.removeClass("mdui-hidden");
            window.switchtime=new Date().getTime();
            $("#holmes-placeholder").addClass('mdui-hidden')
            $("#holmes-placeholder").attr('hidden',"true")
            // console.log("input ")
        
        
    }
});
$("span[var_str]").each((i,ele)=>{
    $(ele).html(Pinyin.GetQP($(ele).attr("var_str")));
})
$("span[var_str_simple]").each((i,ele)=>{
    $(ele).html(Pinyin.GetJP($(ele).attr("var_str_simple")));
})
// console.log("文档刷新时间",<?php echo time();?>)
</script>
</html>
